<link rel="stylesheet" type="text/css" href="assets/bootstrap-datepicker/css/datepicker.css" />
<section id="container" class="">
  <!--main content start-->
  <section id="main-content">
    <section class="wrapper">
      <!--state overview end-->
      <div class="row">
        <div class="col-lg-12">
          <section class="panel">
            <header class="panel-heading">
              拜访记录
            </header>
            <div class="panel-body">
              <form>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">项目名称*</label>
                  <div class="col-sm-10">
                    <input type="text" value="" class="form-control" id="proName" name="proName"/>
                      <input type="hidden" value="" id="proId" name="proId"/>
                  </div>
                </div>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">客户公司名称*</label>
                  <div class="col-sm-10">
                      <input type="text" value="" class="form-control" id="comName" name="comName"/>
                      <input type="hidden" value="" id="comId" name="comId"/>
                  </div>
                </div>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">客户人员名称*</label>
                  <div class="col-sm-10">
                    <input type="text" name="customerName" id="customerName" class="form-control">
                  </div>
                </div>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">拜访日期*</label>
                  <div class="col-sm-10">
                    <input type="text" id="time" class="form-control" name="visitTime">
                  </div>
                </div>
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">拜访内容*</label>
                  <div class="col-sm-10">
                    <textarea class="form-control" id="content" name="content" maxlength="120"></textarea>
                  </div>
                </div>
               
              </form>
            </div>
          </section>

          <section class="panel">
            <div class="panel-body">
                <p class="default-buttons">
                    <a href="javascript:void(0);" class="button-back btn btn-info" onclick="window.history.back()">返回</a>
                    <a href="javascript:void(0);" class="button-next  btn btn-success vsubmit">确认提交</a>
                  </p>
            </div>
          </section>
        </div>
      </div>
    </section>
  </section>
  <!--main content end-->
</section>
<script type="text/javascript" src="assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
<script>
    $('#time').datepicker({
        format: 'yyyy-mm-dd'
    });
    function addVisits(CertusFormAjax) {
        CertusFormAjax.ajax("findProList1",{},function(response){
            var nhlTeams = [];
            var data = response.data;
            for (var i=0;i<data.length;i++){
                var arr={};
                arr.name=data[i].proName;
                arr.id = data[i].id;
                nhlTeams.push(arr);
            }
            //自动补全
            var nhl = $.map(nhlTeams, function (obj) {
                return {
                    value: obj.name,
                    data: { category: obj.id }
                };
            });
            // Initialize autocomplete with local lookup:
            $('#proName').devbridgeAutocomplete({
                lookup: nhl,
                minChars: 1,
                onSelect: function (suggestion) {
                    $("#proId").val(suggestion.data.category);
                },
                showNoSuggestionNotice: true,
                noSuggestionNotice: 'Sorry, no matching results'
            });
        });

        CertusFormAjax.ajax('findCompOName',{},function (response) {
            var nhlTeams = [];
            var data = response.data;
            for (var i=0;i<data.length;i++){
                var arr={};
                arr.name=data[i].comName;
                arr.id = data[i].id;
                nhlTeams.push(arr);
            }
            //自动补全
            var nhl = $.map(nhlTeams, function (obj) {
                return {
                    value: obj.name,
                    data: { category: obj.id }
                };
            });
            // Initialize autocomplete with local lookup:
            $('#comName').devbridgeAutocomplete({
                lookup: nhl,
                minChars: 1,
                onSelect: function (suggestion) {
                    $("#comId").val(suggestion.data.category);
                },
                showNoSuggestionNotice: true,
                noSuggestionNotice: 'Sorry, no matching results'
            });
        });
        $(".vsubmit").on('click',function () {
            if ($("#comId").val()==""){
                layer.msg("请选择客户公司");
                return;
            }

            if ($("#customerName").val()==""){
                layer.msg("请输入客户名称");
                return;
            }
            if ($("#time").val()==""){
                layer.msg("请输入拜访时间");
                return;
            }
            if ($("#userId").val()==""){
                layer.msg("请选择拜访人");
                return;
            }
            if ($("#content").val()==""){
                layer.msg("请输入拜访类容");
                return;
            }
            var arr = $("form").serializeArray();
            var data = {};
            for (var i = 0; i < arr.length; i++) {
                data[arr[i].name] = arr[i].value;
            };
            data.visitTime = $("#time").val();
            data.userId = "0";
            CertusFormAjax.ajax("addVisit", {
                "params": JSON.stringify(data)
            }, function () {
                layer.msg("添加成功");
                window.history.back();
            })
        })
    }
</script>